package com.papercut.inbox;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;

import android.content.Context;

public class NotificationIO {
	
	 private ArrayList<Notification> notificationList;
	
	public ArrayList<Notification> getNotificationList() {
		return notificationList;
	}
	
	Boolean write(ArrayList<Notification> notificationList, FileOutputStream fos) {
		ObjectOutputStream oos;
		try {
			oos = new ObjectOutputStream(fos);
			oos.writeObject(notificationList);
			fos.close();
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	@SuppressWarnings("unchecked")
	Boolean read(Context context) {
		try {
			FileInputStream fis = context.openFileInput(NotificationInbox.FILE_NAME);
			ObjectInputStream ois = new ObjectInputStream(fis);
			notificationList = (ArrayList<Notification>) ois.readObject();
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}

	}
}
